﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ECommerce.WebControls.Productos
{
    public partial class WebDropDownPackages : System.Web.UI.WebControls.DropDownList 
    {
        public int idItemCarrito;
        public int IdItemCarrito
        {
            get { return this.idItemCarrito; }
            set { this.idItemCarrito = value; }
        }        
        public int idProducto;
        public int IdProducto
        {
            get { return this.idProducto; }
            set { this.idProducto = value; }
        }
        public ECommerce.Model.Productos.Package[] packages;
        public ECommerce.Model.Productos.Package[] Packages
        {
            get { return this.packages; }
            set { this.packages = value; }
        }
        public void Load()
        {
            this.Packages = ECommerce.DAO.Cache.Productos.Package.GetPackages();
            if (this.Packages == null)
            {
                this.Packages = ECommerce.DAO.SQL.Productos.Package.GetPackagesDelSistema();
                if (this.Packages.Length > 0)
                    ECommerce.DAO.Cache.Productos.Package.SetPackages(this.Packages);
            }
            this.Load(this.Packages);
        }
        public void Load(int ident)
        {
            this.Packages = ECommerce.DAO.Cache.Productos.Package.GetPackagesByIdProducto(ident);
            if (this.Packages == null)
            {
                this.Packages = ECommerce.DAO.SQL.Productos.Package.GetPackagesByProductoId(ident);
                if (this.Packages.Length > 0)
                    ECommerce.DAO.Cache.Productos.Package.SetPackagesByIdProducto(this.Packages, ident);
            }
            this.Load(this.Packages);
        }
        public void Load(ECommerce.Model.Productos.Package[] Package)
        {
            this.DataSource = Package;
            this.DataMember = "Value";
            this.DataTextField = "Name";
            this.DataValueField = "Value";
            this.DataBind();
        }
        public ECommerce.Model.Productos.Package PackageSeleccionado
        {
            get
            {
                ECommerce.Model.Productos.Package result = new ECommerce.Model.Productos.Package();
                result.Load(Convert.ToInt32(this.SelectedValue));
                return result;
            }
        }
        
    }
}
